<template>
  <div class="collect-page">
    <van-nav-bar fixed title="我的收藏" />
    <van-list
      v-model="loading"
      :finished="finished"
      finished-text="没有更多了"
      @load="onLoad"
    >
      <ArticleItem v-for="item in article" :key="item.id" :article='item'/>
    </van-list>
  </div>
</template>

<script>
import { getCollect } from '@/api/article'
import ArticleItem from '../components/article-item.vue'
export default {
  name: 'collect-page',
  components: {
    ArticleItem
  },
  data() {
    return {
      article: [],
      loading: false,
      finished: false,
      current: 1
    }
  },
  methods: {
    async onLoad() {
      const { data: { data: res } } = await getCollect({
        page: this.current,
        optType: 1,
        pageSize: 10
      })
      this.article.push(...res.rows)
      this.loading = false
      if (this.current === res.pageTotal || !res.rows.length) {
        this.finished = true
      } else {
        this.current++
      }
    }
  }
}
</script>

<style lang="less" scoped>
.collect-page {
  margin-bottom: 50px;
  margin-top: 44px;
}
</style>
